class Solution {
public:
    vector<int> findClosestElements(vector<int>& arr, int k, int x) {
        //关键在于确定左边界
        int l = 0;
        int r = arr.size()-k;
        while(l < r){
            int mid = l+r>>1;
            if(x-arr[mid]>arr[mid+k]-x){
                l = mid+1;
            }else{
                r = mid;
            }
        }
        vector<int>ans  (arr.begin()+l,arr.begin()+l+k);
        return ans;
    }
};